<html>
<head><meta charset="utf-8"><title>https://github.com/rust-lang/wg-allocators/issues/32 · t-libs/wg-allocators · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/index.html">t-libs/wg-allocators</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html">https://github.com/rust-lang/wg-allocators/issues/32</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="180244459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244459">(Nov 08 2019 at 16:12)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> <span class="user-mention" data-user-id="216785">@Tim Diekmann</span> can you provide code for that issue ?</p>



<a name="180244496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244496">(Nov 08 2019 at 16:12)</a>:</h4>
<p>Or a link to the actual places in your own code where you would use that API?</p>



<a name="180244591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244591">(Nov 08 2019 at 16:13)</a>:</h4>
<p>I don't recall at this immediate moment, nor do I care enough to look through my old code.</p>



<a name="180244660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244660">(Nov 08 2019 at 16:14)</a>:</h4>
<p>Like, <code>vec![0; 128]</code> uses <code>Alloc::alloc_zeroed</code></p>



<a name="180244686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244686">(Nov 08 2019 at 16:14)</a>:</h4>
<p><code>Vec::from_raw_parts</code> works</p>



<a name="180244708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244708">(Nov 08 2019 at 16:15)</a>:</h4>
<p>sure, so why can't the public use alloc zeroed with the initial vec too</p>



<a name="180244728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244728">(Nov 08 2019 at 16:15)</a>:</h4>
<p>They can, <code>Vec::from_raw_parts</code> allows that</p>



<a name="180244760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244760">(Nov 08 2019 at 16:15)</a>:</h4>
<p>What problem does it motivate adding an extra API for solving this particular problem only, when we have like 3 ways to solve it ?</p>



<a name="180244772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244772">(Nov 08 2019 at 16:15)</a>:</h4>
<p>from_raw_parts is a degenerate fallback for when the type authors haven't had time to give you enough good stuff</p>



<a name="180244874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244874">(Nov 08 2019 at 16:16)</a>:</h4>
<p><code>Vec&lt;NonZeroU8&gt;::with_capacity_zeroed</code> makes no sense</p>



<a name="180244888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244888">(Nov 08 2019 at 16:16)</a>:</h4>
<p>surr</p>



<a name="180244895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244895">(Nov 08 2019 at 16:16)</a>:</h4>
<p>i agree</p>



<a name="180244928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244928">(Nov 08 2019 at 16:17)</a>:</h4>
<p>if you want the <code>vec![0; N]</code> optimization, there are a billion different ways to allow you to use that</p>



<a name="180244952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244952">(Nov 08 2019 at 16:17)</a>:</h4>
<p>but one needs to know which problem precisely you have that warrants it to choose the right one</p>



<a name="180244967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244967">(Nov 08 2019 at 16:17)</a>:</h4>
<p>well, this is just one method</p>



<a name="180244978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180244978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180244978">(Nov 08 2019 at 16:17)</a>:</h4>
<p>and people will live without it</p>



<a name="180245040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180245040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180245040">(Nov 08 2019 at 16:18)</a>:</h4>
<p><span class="user-mention" data-user-id="216785">@Tim Diekmann</span> had the problem as well, so apparently there are enough people running into this issue</p>



<a name="180245068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180245068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180245068">(Nov 08 2019 at 16:18)</a>:</h4>
<p>which means that solving it might be worth doing</p>



<a name="180245077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180245077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180245077">(Nov 08 2019 at 16:18)</a>:</h4>
<p>personally? I avoid using the vec macro</p>



<a name="180245081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180245081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180245081">(Nov 08 2019 at 16:18)</a>:</h4>
<p>always i avoid it</p>



<a name="180245091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180245091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180245091">(Nov 08 2019 at 16:18)</a>:</h4>
<p>if i see i used it i usually go remove it later</p>



<a name="180245146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180245146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180245146">(Nov 08 2019 at 16:19)</a>:</h4>
<p><code>let mut x: Vec::new(); x.resize(0, 42);</code> uses <code>Alloc::alloc_zeroed</code> as well</p>



<a name="180245158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180245158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180245158">(Nov 08 2019 at 16:19)</a>:</h4>
<p>IIRC</p>



<a name="180245242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180245242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180245242">(Nov 08 2019 at 16:20)</a>:</h4>
<p>there is a trait that you can implement for types for which a particular value has a more efficient allocation pattern for bulk allocations</p>



<a name="180245443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180245443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180245443">(Nov 08 2019 at 16:22)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/master/src/liballoc/vec.rs#L1698" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/liballoc/vec.rs#L1698">https://github.com/rust-lang/rust/blob/master/src/liballoc/vec.rs#L1698</a></p>



<a name="180245454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180245454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180245454">(Nov 08 2019 at 16:22)</a>:</h4>
<p>You can specialize it in your own crate for your own types</p>



<a name="180245473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180245473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180245473">(Nov 08 2019 at 16:22)</a>:</h4>
<p>A dang, it's private, maybe it should be public</p>



<a name="180246369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180246369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180246369">(Nov 08 2019 at 16:32)</a>:</h4>
<p>the standard library has long needed a ZeroedSafe trait</p>



<a name="180246384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180246384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180246384">(Nov 08 2019 at 16:32)</a>:</h4>
<p>it's so simple that no one can agree on doing it</p>



<a name="180247177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180247177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180247177">(Nov 08 2019 at 16:40)</a>:</h4>
<p>people want to use it to initialize statics, and that requires it be a const fn</p>



<a name="180247192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180247192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180247192">(Nov 08 2019 at 16:40)</a>:</h4>
<p>but const fns are not supported in traits</p>



<a name="180247260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180247260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180247260">(Nov 08 2019 at 16:40)</a>:</h4>
<p>so it isn't that simple</p>



<a name="180247356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180247356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180247356">(Nov 08 2019 at 16:41)</a>:</h4>
<p>(but yeah, could be done with enough magic, e.g. , <code>const fn mem::zeroed_safe&lt;T: ZeroedSafe&gt;() -&gt; T</code> that's an intrinsic or similar and making <code>ZeroedSafe</code> an <code>auto trait</code>, etc.)</p>



<a name="180247477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180247477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180247477">(Nov 08 2019 at 16:42)</a>:</h4>
<p>The problem is that zeroing the memory when allocating with a <code>Vec</code> is pointless if you are not going to exploit it later, e.g., by using <code>Vec::set_len</code></p>



<a name="180247506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180247506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180247506">(Nov 08 2019 at 16:43)</a>:</h4>
<p>and then there is the difference in whether you want to always exploit it, so every reallocation should zero memory</p>



<a name="180247519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180247519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180247519">(Nov 08 2019 at 16:43)</a>:</h4>
<p>and when you only want to exploit it once at the beginning</p>



<a name="180247925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180247925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180247925">(Nov 08 2019 at 16:46)</a>:</h4>
<p>I personally think that we should have better support for <code>Box&lt;[T]&gt;</code>, better conversions from/to <code>Vec&lt;T&gt;</code> and <code>Box&lt;[T]&gt;</code>, and better support for <code>T: ZeroedSafe</code>, and with that, you get this for free:</p>
<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="nc">Foo</span><span class="p">(</span><span class="kt">i32</span><span class="p">);</span><span class="w"> </span><span class="c1">// ZeroedSafe due to the auto trait</span>
<span class="kd">let</span><span class="w"> </span><span class="n">vec</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="n">Foo</span><span class="p">,</span><span class="w"> </span><span class="n">A</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Box</span>::<span class="n">array</span><span class="p">(</span><span class="n">Foo</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span><span class="w"> </span><span class="n">N</span><span class="p">).</span><span class="n">into</span><span class="p">();</span><span class="w"></span>
</pre></div>



<a name="180248079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180248079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180248079">(Nov 08 2019 at 16:48)</a>:</h4>
<p><code>Box::array</code> can just do the same optimization that <code>Vec</code> internally does, if <code>Foo: ZeroedSafe</code> and if the value passed is all zeros, then just use <code>A::alloc_zeroed</code>.</p>



<a name="180248172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180248172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180248172">(Nov 08 2019 at 16:49)</a>:</h4>
<p>And well <code>vec![Foo(0); N]</code> would just expand to that and it would "just work"</p>



<a name="180248973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180248973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180248973">(Nov 08 2019 at 16:56)</a>:</h4>
<p>1) it would have no methods<br>
2) if zeroed isn't const that's an absolute failure of the standard library</p>



<a name="180249076"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180249076" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180249076">(Nov 08 2019 at 16:57)</a>:</h4>
<p>the biggest problem is that while the vec![0; 50] version will happen to do what I want, it's completely opaque that something special is happening compared to my performance compared to vec![2; 50]</p>



<a name="180249515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180249515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180249515">(Nov 08 2019 at 17:01)</a>:</h4>
<p>rather, i am well aware that zeroed isn't currently const, but if they refuse to make it const that's a total failure state for the library to end up in.</p>



<a name="180253317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180253317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180253317">(Nov 08 2019 at 17:40)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> <code>mem::zeroed</code> isn't const fn today</p>



<a name="180253343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180253343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180253343">(Nov 08 2019 at 17:41)</a>:</h4>
<p>ah yep</p>



<a name="180253480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180253480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180253480">(Nov 08 2019 at 17:42)</a>:</h4>
<blockquote>
<p>it's completely opaque that something special is happening compared to my performance compared to vec![2; 50]</p>
</blockquote>
<p>Why should people have to write different code to get the optimization ?</p>



<a name="180253524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180253524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180253524">(Nov 08 2019 at 17:43)</a>:</h4>
<p>If instead of a macro it would be a method <code>Vec::new_with(val:T, size: usize,)</code> the behavior would be identical</p>



<a name="180253569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180253569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180253569">(Nov 08 2019 at 17:43)</a>:</h4>
<p><code>Vec::new_with(0, 50)</code> would be "fast" and <code>Vec::new_with(42, 50)</code> would be "slow"</p>



<a name="180253654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180253654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180253654">(Nov 08 2019 at 17:44)</a>:</h4>
<p>I'm not sure what alternative you are thinking of instead</p>



<a name="180253716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180253716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180253716">(Nov 08 2019 at 17:45)</a>:</h4>
<p>Either way, given an API that does the fast thing, adding a second API to do the same thing would not add as much value</p>



<a name="180253957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180253957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180253957">(Nov 08 2019 at 17:48)</a>:</h4>
<p>Also, the macro API solves many more problems than a method based API</p>



<a name="180254220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180254220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180254220">(Nov 08 2019 at 17:51)</a>:</h4>
<p>So currently we provide <code>vec![Foo; N]</code> that does what you want for some types, and also <code>Vec::from_raw_parts</code> that lets you exploit any feature that whatever allocator you are using supports. Supporting <code>vec![Foo; N]</code> for more types feels simpler to me from an extension point-of-view.</p>



<a name="180254373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180254373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180254373">(Nov 08 2019 at 17:53)</a>:</h4>
<p>using the macro or a method should do the optimization if it can obviously</p>



<a name="180254407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180254407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180254407">(Nov 08 2019 at 17:53)</a>:</h4>
<p>but having a method that _forces_ the optimization and the expense of being less general is good</p>



<a name="180254443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180254443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180254443">(Nov 08 2019 at 17:53)</a>:</h4>
<p>then you know that if you change the design to the point where you can't use the old method, you might be giving up some performance</p>



<a name="180254517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180254517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180254517">(Nov 08 2019 at 17:54)</a>:</h4>
<p>it should _not_ be the case that new_with(5) and new_with(0) are both slow, that's stupid</p>



<a name="180254571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180254571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180254571">(Nov 08 2019 at 17:55)</a>:</h4>
<p>but if you care to go get that optimization you should know when you just made yourself ineligible for it later (possibly on accident)</p>



<a name="180256059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180256059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180256059">(Nov 08 2019 at 18:13)</a>:</h4>
<p>make a concrete proposal, but adding a new API has a cost, and it's not obvious to me that the cost is worth it</p>



<a name="180256145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180256145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180256145">(Nov 08 2019 at 18:14)</a>:</h4>
<p>something like <code>fn zeroed_vec&lt;T: Zeroable&gt;(size: usize) -&gt; Vec&lt;T&gt; { vec![T::zeroed(); size] }</code> does the trick</p>



<a name="180256297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180256297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180256297">(Nov 08 2019 at 18:16)</a>:</h4>
<p>(it generates a compilation time error if <code>T</code> happens to not be <code>Zeroable</code>)</p>



<a name="180256375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180256375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180256375">(Nov 08 2019 at 18:17)</a>:</h4>
<p>also, none of this guarantees the optimization</p>



<a name="180256393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180256393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180256393">(Nov 08 2019 at 18:17)</a>:</h4>
<p>if your allocator dispatches the <code>Alloc::alloc_zeroed</code> method to <code>Alloc::alloc</code> + manual zeroing, you won't get it</p>



<a name="180256466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180256466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180256466">(Nov 08 2019 at 18:18)</a>:</h4>
<p>If you really want to be sure to get the optimization, using <code>Vec::from_raw_parts</code> while calling the allocator directly is probably the only choice</p>



<a name="180257033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180257033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180257033">(Nov 08 2019 at 18:24)</a>:</h4>
<p>"an API" makes it sound huge, but really it's one method</p>



<a name="180259270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180259270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180259270">(Nov 08 2019 at 18:48)</a>:</h4>
<p>Another choice would be an extension trait. Simple and not needed in std/alloc itself</p>



<a name="180611198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180611198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180611198">(Nov 13 2019 at 10:28)</a>:</h4>
<blockquote>
<p>"an API" makes it sound huge, but really it's one method</p>
</blockquote>
<p>Its' just one of many methods one might add. For example, <code>Vec::new()</code> is a const fn, so you might want to use <code>Vec::new()</code> to get a Vec, and then use <code>Vec::resize_zeroed</code> in the first allocation.</p>



<a name="180611285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180611285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180611285">(Nov 13 2019 at 10:29)</a>:</h4>
<p>And so on, e.g., if you are using the <code>Vec</code> to implement a <code>Deque</code>, and want to pass the [tail, head] "uninitialized" slice to, e.g., the <code>Bytes</code> crate, then you want <code>[tail, head]</code> to always be zeroed, so you probably want to call <code>Vec::push_zeroed</code> within the <code>Deque</code> to implement <code>Deque::push_back</code>, etc.</p>



<a name="180611411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/https%3A//github.com/rust-lang/wg-allocators/issues/32/near/180611411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/https.3A.2F.2Fgithub.2Ecom.2Frust-lang.2Fwg-allocators.2Fissues.2F32.html#180611411">(Nov 13 2019 at 10:31)</a>:</h4>
<blockquote>
<p>Another choice would be an extension trait. Simple and not needed in std/alloc itself</p>
</blockquote>
<p>That's an option, but for some users adding a crate just to obtain an extension trait for this is probably overkill.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>